From a1af03bac4a3d2c9bd8087359387c7d843a5547a Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Tue, 15 Mar 2005 19:21:16 +0000 Subject: [PATCH] bitkeeper revision 1.1236.34.7 (423735acABhfn7rysHwGJkcVOLD6GA) XCS cleanups. Signed-off-by: Keir Fraser --- tools/misc/xend | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/misc/xend b/tools/misc/xend index 6ad368ca9d..6360a35aeb 100644 --- a/tools/misc/xend +++ b/tools/misc/xend @@ -101,11 +101,16 @@ def check_user(): def xcs_running(): """ See if the control switch is running. """ + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - xcs_pidfile = open(XCS_PIDFILE) - except IOError: - return(0) - xcs_pidfile.close() + s.connect( (XCS_PATH) ) + s.close() + except: + try: + os.remove(XCS_PIDFILE) + except: + pass + return 0 return 1 def start_xcs(): @@ -113,6 +118,8 @@ def start_xcs(): if os.fork(): time.sleep(0.1) # let xcs start else: + if not os.path.isdir(os.path.dirname(XCS_PATH)): + os.makedirs(os.path.dirname(XCS_PATH)) try: os.execvp(XCS_EXEC, XCS_ARGS) except: @@ -129,12 +136,11 @@ def start_xcs(): def stop_xcs(): try: xcs_pidfile = open(XCS_PIDFILE) - except IOError: - return - xcs_pid = int(xcs_pidfile.read().strip()) - os.kill(xcs_pid, signal.SIGTERM) - xcs_pidfile.close() - + xcs_pid = int(xcs_pidfile.read().strip()) + os.kill(xcs_pid, signal.SIGTERM) + xcs_pidfile.close() + except: + return def main(): try: -- 2.30.2